<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="username">
    <input type="text" id="age">
    <input type="text" id="sex">
    <script>
        // var str=localStorage.getItem("user");//string
        // var user=JSON.parse(str);//将字符串转换为对象

        var user=JSON.parse(localStorage.getItem("user"));
        document.getElementById("username").value=user.username;
        document.getElementById("age").value=user.age;
        document.getElementById("sex").value=user.sex;
    </script>
</body>
</html>